package com.itheima.controller.admin;

import com.itheima.common.result.PageResult;
import com.itheima.common.result.Result;
import com.itheima.dto.YddArticlePageQueryDTO;
import com.itheima.pojo.YddArticle;
import com.itheima.service.YddArticleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ydd_article")
public class YddArticleController {

    @Autowired
    YddArticleService yddArticleService;

    /**
     * 文章列表-分页
     * @param dto
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("文章列表-分页")
    public Result<PageResult> list(YddArticlePageQueryDTO dto){
        PageResult page = yddArticleService.PageQuery(dto);
        return Result.success(page);
    }

    /**
     * 文章删除
     * @param id
     * @return
     */
    @GetMapping("del")
    @ApiOperation("文章删除")
    public Result delArticle(String id){
        yddArticleService.removeById(id);
        return Result.success();
    }

    /**
     * 文章详情
     * @param id
     * @return
     */
    @GetMapping("rowInfo")
    @ApiOperation("文章详情")
    public Result rowInfoArticle(String id){
        YddArticle yddArticle = yddArticleService.rouInfoArticle(id);
        return Result.success(yddArticle);
    }

    /**
     * 文章添加
     * @param yddArticle
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("文章添加")
    public Result addArticle(@RequestBody YddArticle yddArticle){
        yddArticleService.addArticle(yddArticle);
        return Result.success();
    }

    /**
     * 文章修改
     * @param yddArticle
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("文章修改")
    public Result updateArticle(@RequestBody YddArticle yddArticle){
        yddArticleService.updateArticle(yddArticle);
        return Result.success();
    }
}
